package net.zoneland.zrdp.biz.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import net.zoneland.zrdp.biz.domain.AuditTarget;
import net.zoneland.zrdp.biz.service.IAuditTargetService;
import net.zoneland.zrdp.common.annotation.Log;
import net.zoneland.zrdp.common.core.controller.BaseController;
import net.zoneland.zrdp.common.core.domain.AjaxResult;
import net.zoneland.zrdp.common.enums.BusinessType;
import net.zoneland.zrdp.common.utils.poi.ExcelProcessor;

/**
 * 审计对象数据Controller.
 * 创建日期: 2024-03-14
 * @author helu
 */
@RestController
@RequestMapping("/biz/target")
public class AuditTargetController extends BaseController {

    /** 审计对象excel模板标题行数. */
    private static final int EXCEL_TITLE_ROW = 3;

    @Resource
    private IAuditTargetService auditTargetService;

    /**
     * 导入审计对象.
     * @author helu
     * @Date 13:46 2024/5/10
     * @param file 导入的文件
     * @return net.zoneland.zrdp.common.core.domain.AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('biz:target:import')")
    @Log(title = "审计对象", businessType = BusinessType.IMPORT)
    @PostMapping("/import-data")
    public AjaxResult importData(final MultipartFile file) throws Exception {
        //从excel获取审计数据
        final List<AuditTarget> list = new ExcelProcessor<>(AuditTarget.class)
            .importExcel(file.getInputStream(), EXCEL_TITLE_ROW);

        //导入审计对象数据
        return success(auditTargetService.importAuditTargets(list));
    }
}
